<template>
  <el-cascader
    :value="value"
    :options="options"
    :props="props"
    clearable
    @change="handleChange"
  />

</template>

<script>
import { department } from '@/api/user'
import { transListToTreeData } from '@/utils/arr'
export default {
  props: {
    value: {
      type: Number,
      required: true
    }
  },
  data() {
    return {
      props: {
        label: 'name', // 要展示的字段
        value: 'id' // 要存储的字段
      },
      list: [],

      options: [
      ]
    }
  },
  async created() {
    this.getdata()

    // console.log(this.$route.params.id)
  },
  methods: {
    async getdata() {
      const res = await department()
      console.log(res)
      this.list = res.data
      // transListToTreeData(this.list, 0)
      this.options = transListToTreeData(this.list, 0)
    },
    handleChange(value) {
      console.log(value)
      const id = value[value.length - 1]
      this.$emit('input', id)
    }
  }}
</script>

<style>

</style>
